import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
      count: 100
    },
    getters:{
        evenOrOdd(state){
            return state.count%2==0? '偶数' : '奇数'
        }
    },
    mutations: {
        add(state){
            state.count += 1
        },
        sub(state){
            state.count -= 1
        }
    },
    actions:{
        add({ commit }){
            commit('add')
        },
        sub({ commit }){
            commit('sub')
        },
        asyncAdd ({ commit }) {
            setTimeout(() => {
              commit('add')
            }, 1000)
        }
    }
})

export default store